package com.fanghuaiming.seata.order.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import java.math.BigDecimal;

/****
 * @description: 订单TCC接口
 * @version:1.0.0
 * @author fanghuaiming
 * @data Created in 2020/11/30 下午4:51
 *
 */
@LocalTCC
public interface SeataPhaseTccOrder {

    /**
     * @Description: Try
     *
     * 第一阶段的方法
     * 通过注解指定第二阶段的两个方法名
     * BusinessActionContext 上下文对象，用来在两个阶段之间传递数据
     *  @BusinessActionContextParameter 注解的参数数据会被存入 BusinessActionContext
     *
     * @param:
     * @return:
     * @auther: fanghuaiming
     * @date: 2020/11/30 下午4:57
     * @version:1.0.0
     */
    @TwoPhaseBusinessAction(name = "seataPhaseTccOrder",commitMethod = "commit",rollbackMethod = "rollback")
    Boolean prepareCreateOrder(BusinessActionContext businessActionContext,
            @BusinessActionContextParameter(paramName = "orderId") Long orderId,
            @BusinessActionContextParameter(paramName = "userId") Long userId,
            @BusinessActionContextParameter(paramName = "productId") Long productId,
            @BusinessActionContextParameter(paramName = "count") Integer count,
            @BusinessActionContextParameter(paramName = "money") BigDecimal money);

    /**
     * @Description: Confirm
     *  第二阶段 - 提交
     * @param:
     * @return:
     * @auther: fanghuaiming
     * @date: 2020/11/30 下午4:55
     * @version:1.0.0
     */
    boolean commit(BusinessActionContext businessActionContext);

    /**
     * @Description: Cancel
     *  第二阶段回滚
     * @param:
     * @return:
     * @auther: fanghuaiming
     * @date: 2020/11/30 下午4:56
     * @version:1.0.0
     */
    boolean rollback(BusinessActionContext businessActionContext);
}
